<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <input type="hidden" name="id" th:value="${userInfo.id}" />
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="name"  th:value="${userInfo.name}" lay-verify="title" autocomplete="off" placeholder="您的真实姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="0" title="男" th:checked="${userInfo.sex==0}">
                        <input type="radio" name="sex" value="1" title="女" th:checked="${userInfo.sex==1}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">年龄</label>
                    <div class="layui-input-block">
                        <input type="number"  name="age" th:value="${userInfo.age}" lay-verify="title" autocomplete="off" placeholder="年龄" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="text"  name="phoneNum"  th:value="${userInfo.phoneNum}"  lay-verify="phone" autocomplete="off" placeholder="电话" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱</label>
                    <div class="layui-input-block">
                        <input type="text"  name="email" th:value="${userInfo.email}" lay-verify="email" autocomplete="off" placeholder="邮箱" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">地址</label>
                    <div class="layui-input-block">
                        <input type="text"  name="address" th:value="${userInfo.address}" lay-verify="" autocomplete="off" placeholder="地址" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item" shiro:hasAnyRoles="admin,super_admin">
                    <label class="layui-form-label">信息状态</label>
                    <div class="layui-input-block">
                        <select id="status" name="status" class="valid">
                            <p th:if="${userInfo.status== 0}">
                                <option value="0">正常</option>
                                <option value="1">其他</option>
                            </p>
                            <p th:if="${userInfo.status== 1}">
                                <option value="1">其他</option>
                                <option value="0">正常</option>
                            </p>
                        </select>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
<!--            <button type="reset" class="pear-btn pear-btn-sm">-->
<!--                <i class="layui-icon layui-icon-refresh"></i>-->
<!--                重置-->
<!--            </button>-->
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
layui.use(['form','jquery'],function(){
    let form = layui.form;
    let $ = layui.jquery;

    form.on('submit(user-save)', function(data){
        $.ajax({
            type: 'post', // 提交方式 get/post
            url: '/user-info/updateUserInfo', // 需要提交的 url
            data: {
                id: $('input[name=id]').val(),
                name: $('input[name=name]').val(),
                sex: $('input[name=sex]:checked').val(),
                age: $('input[name=age]').val(),
                phoneNum: $('input[name=phoneNum]').val(),
                email: $('input[name=email]').val(),
                address: $('input[name=address]').val(),
                status: $('#status').val()
            },
            dataType:'json',
            success:function(result){

                layer.msg('修改成功',{icon:1,time:500},function(){
                    parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("user-table");
                });

                // if(result.success){
                //     layer.msg('修改成功',{icon:1,time:1000},function(){
                //         parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                //         parent.layui.table.reload("user-table");
                //     });
                // }else{
                //     layer.msg(result.msg,{icon:2,time:1000});
                // }
            },
            error:function (data) {
                console.log("error")
            }
        });
        return false; // 阻止表单自动提交事件，必须返回false，否则表单会自己再做一次提交操作，并且页面跳转

        // let roleIds = "";
        // $('input[type=checkbox]:checked').each(function() {
        //     roleIds += $(this).val()+",";
        // });
        // roleIds = roleIds.substr(0,roleIds.length-1);
        // data.field.roleIds = roleIds;
        //
        // $.ajax({
        //     url:'/system/user/save',
        //     data:JSON.stringify(data.field),
        //     dataType:'json',
        //     contentType:'application/json',
        //     type:'post',
        //     success:function(result){
        //         if(result.success){
        //             layer.msg(result.msg,{icon:1,time:1000},function(){
        //                 parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
        //                 parent.layui.table.reload("user-table");
        //             });
        //         }else{
        //             layer.msg(result.msg,{icon:2,time:1000});
        //         }
        //     }
        // })
        // return false;
    });
})
</script>
<script>
</script>
</body>
</html>
